xxxxxxxxxx
//Another online linux C compiler with working fork/pipe/etc...
https://www.onlinegdb.com/online_c_compiler
xxxxxxxxxx
//Online linux C compiler with working fork
https://rextester.com/l/c_online_compiler_gcc
xxxxxxxxxx
#include <stdio.h>
#include <unistd.h>
int main()
{
int id = fork();
if (id < 0)
printf("Fork failure\n");
else if (id == 0)
printf("Inside child: Pid of Parent Process: %d ::Pid of Child Process: %d\n\n", getppid(), getpid());
else
printf("Inside Parent: Pid of Parent Process: %d ::Pid of Child Process: %d\n\n", getpid(), id);
return 0;
}
xxxxxxxxxx
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
int main(void){
int i;
uid_t id = geteuid();
struct utsname whoami;
i = uname(&whoami); /* hold the structure */
if ( i == 0 ){
printf("Operating system name : %s\n",whoami.whoami);
}
xxxxxxxxxx
#!/bin/bash
# Purpose - Script to add a user to Linux system including passsword
# Author - Vivek Gite <www.cyberciti.biz> under GPL v2.0+
# ------------------------------------------------------------------
# Am i Root user?
if [ $(id -u) -eq 0 ]; then
read -p "Enter username : " username
read -s -p "Enter password : " password
egrep "^$username" /etc/passwd >/dev/null
if [ $? -eq 0 ]; then
echo "$username exists!"
exit 1
else
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password)
useradd -m -p "$pass" "$username"
[ $? -eq 0 ] && echo "User has been added to system!" || echo "Failed to add a user!"
fi
else
echo "Only root may add a user to the system."
exit 2
fi